#include "QtSpinner.h"
#include <QPainter>
#include "QtBlendToEffect.h"
#include "QtSequentialAnimationEffect.h"
#include "QtScaleToEffect.h"
#include "QtRotateToEffect.h"

QtSpinner::QtSpinner(const Direction& direction, QtSprite *parent): QtCellSprite(parent), duration(1000), spinDirection(direction)
{
	SetForegroundResource();
}

QtSpinner::~QtSpinner()
{
}


void QtSpinner::SetDirection(const Direction& direction)
{
	spinDirection = direction;

	SetForegroundResource();
}

void QtSpinner::SetForegroundResource()
{
	SetResource("foreground", "spinner");
	AddResourceSpecification("foreground", spinDirection.ToString());
}


void QtSpinner::Rotate()
{
	if (spinDirection.IsWest())
	{		
		qreal newAngle = Angle() - 90;
		if (newAngle < 360)
			newAngle += 360;
		RotateLeftTo(newAngle, duration);

		Start();
	}
	else if (spinDirection.IsEast())
	{
		qreal newAngle = Angle() + 90;
		if (newAngle > 360)
			newAngle -= 360;
		RotateRightTo(newAngle, duration);

		Start();
	}
}




